<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Forum manager</title>
        <script type="text/javascript">
            function setFirstUserSelected() {
                var event = document.createEvent("HTMLEvents");
                event.initEvent("change", true, true);
                document.getElementById("userList").dispatchEvent(event);
            }
        </script>
        <script type="text/javascript">
            function setFirstThreadSelected() {
                var event = document.createEvent("HTMLEvents");
                event.initEvent("change", true, true);
                document.getElementById("threadList").dispatchEvent(event);
            }
        </script>
        <script type="text/javascript">
            function setFirstMessageSelected() {
                var event = document.createEvent("HTMLEvents");
                event.initEvent("change", true, true);
                document.getElementById("messageList").dispatchEvent(event);
            }
        </script>
    </h:head>
    <h:body onload="setFirstUserSelected(); setFirstThreadSelected(); setFirstMessageSelected()">
        <!-- User section -->
        <h3>User section</h3>
        <h:form>
            Search user by <i>name</i> parameter:
            <br/>
            <h:inputText size="10" value="#{user.searchParameter}" /> &nbsp;
            <h:commandButton value="Search" actionListener="#{user.search}" action="#{user.getAction}"/>
        </h:form>
        <br/>
        <h:form prependId="false">
            <table>
                <tr>
                    <td>
                        <h:selectOneMenu id="userList" value="#{user.selectedUserId}">
                            <f:selectItems value="#{user.allUsers}" />
                            <f:ajax render="name regDate login password info" listener="#{user.setCurrentUser}"/>
                        </h:selectOneMenu>
                    </td>
                    <td>
                        <h:commandButton value="Add" actionListener="#{user.unsetCurrentUser}" action="#{user.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Edit" actionListener="#{user.ensureCurrentUserSet}" action="#{user.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Delete" actionListener="#{user.delete}" action="#{user.getAction}"/>
                    </td>
                </tr>
            </table>
            <b>Name: </b>
            <h:outputText id="name" value="#{user.name}"/>
            <br/>
            <b>Reg. date: </b>
            <h:outputText id="regDate" value="#{user.registrationDate}">
                <f:convertDateTime timeZone="GMT+04:00" pattern="MMM d, yyyy HH:mm:ss"/>
            </h:outputText>
            <br/>
            <b>Login: </b>
            <h:outputText id="login" value="#{user.login}"/>
            <br/>
            <b>Password: </b>
            <h:outputText id="password" value="#{user.password}"/>
            <br/>
            <b>Info: </b>
            <h:outputText id="info" value="#{user.info}"/>
        </h:form>
        <br/>
        <hr/>
        <!-- Thread section -->
        <h3>Thread section</h3>
        <h:form>
            Search thread by <i>caption</i> parameter:
            <br/>
            <h:inputText size="10" value="#{thread.searchParameter}" /> &nbsp;
            <h:commandButton value="Search" actionListener="#{thread.search}" action="#{thread.getAction}"/>
        </h:form>
        <br/>
        <h:form prependId="false">
            <table>
                <tr>
                    <td>
                        <h:selectOneMenu id="threadList" value="#{thread.selectedThreadId}">
                            <f:selectItems value="#{thread.allThreads}" />
                            <f:ajax render="id threadCaption" listener="#{thread.setCurrentThread}"/>
                        </h:selectOneMenu>
                    </td>
                    <td>
                        <h:commandButton value="Add" actionListener="#{thread.unsetCurrentThread}" action="#{thread.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Edit" actionListener="#{thread.ensureCurrentThreadSet}" action="#{thread.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Delete" actionListener="#{thread.delete}" action="#{thread.getAction}"/>
                    </td>
                </tr>
            </table>
            <b>Id: </b>
            <h:outputText id="id" value="#{thread.id}"/>
            <br/>
            <b>Caption: </b>
            <h:outputText id="threadCaption" value="#{thread.caption}"/>
        </h:form>
        <br/>
        <hr/>

        <!-- Message section -->
        <h3>Message section</h3>
        <h:form>
            Search message by <i>caption</i> parameter:
            <br/>
            <h:inputText size="10" value="#{message.searchParameter}" /> &nbsp;
            <h:commandButton value="Search" actionListener="#{message.search}" action="#{message.getAction}"/>
        </h:form>
        <br/>
        <h:form prependId="false">
            <table>
                <tr>
                    <td>
                        <h:selectOneMenu id="messageList" value="#{message.selectedMessageId}">
                            <f:selectItems value="#{message.allMessages}" />
                            <f:ajax render="messageCaption postDate text userId threadId" listener="#{message.setCurrentMessage}"/>
                        </h:selectOneMenu>
                    </td>
                    <td>
                        <h:commandButton value="Add" actionListener="#{message.unsetCurrentMessage}" action="#{message.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Edit" actionListener="#{message.ensureCurrentMessageSet}" action="#{message.getAction}"/>
                    </td>
                    <td>
                        <h:commandButton value="Delete" actionListener="#{message.delete}" action="#{message.getAction}"/>
                    </td>
                </tr>
            </table>
            <b>Caption: </b>
            <h:outputText id="messageCaption" value="#{message.caption}"/>
            <br/>
            <b>Post date: </b>
            <h:outputText id="postDate" value="#{message.postDate}">
                <f:convertDateTime timeZone="GMT+04:00" pattern="MMM d, yyyy HH:mm:ss"/>
            </h:outputText>
            <br/>
            <b>Text: </b>
            <h:outputText id="text" value="#{message.text}"/>
            <br/>
            <b>User id: </b>
            <h:outputText id="userId" value="#{message.userId}"/>
            <br/>
            <b>Thread id: </b>
            <h:outputText id="threadId" value="#{message.threadId}"/>
        </h:form>
        <br/>
    </h:body>
</html>
